package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.entity.SysWelfareCenter;
import com.hl.sfzy.mapper.SysWelfareCenterMapper;
import com.hl.sfzy.service.SysWelfareCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("sysWelfareCenterService")
public class SysWelfareCenterServiceImpl implements SysWelfareCenterService {
    @Autowired
    private SysWelfareCenterMapper sysWelfareCenterMapper;
    @Override
    public int add(SysWelfareCenter entity) {
        return sysWelfareCenterMapper.insert(entity);
    }

    @Override
    public int edit(SysWelfareCenter entity) {
        return sysWelfareCenterMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysWelfareCenterMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysWelfareCenterMapper.deleteBatch(ids);
    }

    @Override
    public List<SysWelfareCenter> find(SysWelfareCenter entity) {
        return sysWelfareCenterMapper.select(entity);
    }

    @Override
    public SysWelfareCenter findById(Integer id) {
        return sysWelfareCenterMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysWelfareCenter entity) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        //当前页数据
        List<SysWelfareCenter> list = sysWelfareCenterMapper.select(entity);
        //分页信息对象
        PageInfo<SysWelfareCenter> pageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        //map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        return map;
    }
}
